#include "lv_port.h"
#include "rgb_lcd.h"

static void touchpad_read(lv_indev_t * indev, lv_indev_data_t * data);

lv_indev_t * indev_touchpad;

void lv_port_indev_init(void)
{
    touchInit();

    indev_touchpad = lv_indev_create();
    lv_indev_set_type(indev_touchpad, LV_INDEV_TYPE_POINTER);
    lv_indev_set_read_cb(indev_touchpad, touchpad_read);
}

static void touchpad_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
{
    static int32_t last_x = 0;
    static int32_t last_y = 0;

    if (scan()) {
        last_x = touch_x;
        last_y = touch_y;
        data->state = LV_INDEV_STATE_PR;
    } else {
        data->state = LV_INDEV_STATE_REL;
    }

    data->point.x = last_x;
    data->point.y = last_y;
}

